#ifndef SYSTEM_H
#define SYSTEM_H

#include "..\Database\Database.h"

// DEFINISI PERINTAH MODUS 1
#define LOAD_COMMAND		CharToString("Load")
#define OPEN_COMMAND		CharToString("Open")
#define SAVE_COMMAND		CharToString("Save")
#define ADDSITE_COMMAND		CharToString("AddSite")
#define ADDCONN_COMMAND		CharToString("AddConn")
#define CREATE_COMMAND		CharToString("Create") // Create Tabel
#define RESET_COMMAND		CharToString("Reset")
#define LIST_COMMAND		CharToString("List")

// DEFINISI PERINTAH MODUS 2
#define RETRIEVE_COMMAND	CharToString("Retrieve")
#define INSERT_COMMAND		CharToString("Insert")
#define DELETE_COMMAND		CharToString("Delete")
#define UPDATE_COMMAND		CharToString("Update")

// DEFINISI PERINTAH UMUM
#define HELP__COMMAND		CharToString("HELP")
#define EXIT_COMMAND		CharToString("Exit")
#define CLOSE_COMMAND		CharToString("Close")

// Global Var
string		SOURCEFILE;
#define 	UNDEFINEDFILE 	CharToString("OGLIESVIRL")
TabelMhs	TABELMHS;
TabelMK		TABELMK;
TabelPMK	TABELPMK;
nodeAddress	ACTIVENODE;
nodeList	NODELIST;
edgeList	EDGELIST;
int			MODUS;
#define SELESAI		0
#define PERSIAPAN	1
#define SIMULASI	2

// MAIN LOOP DEFINED :
#define LOOPSYSTEM	while(MODUS!=SELESAI)

// PROSEDUR UMUM
void InitSystem();
void GetUserInput();
void ParseUserInput(Reader R);
void ChangeModus(int modus);


// PROSEDUR MODUS PERSIAPAN
void ParseCommand_PersiapanMode(Reader R);

void ParseLoadCommand(Reader R);
bool LoadFile(string filename);
bool LoadNodes(FILE *f);
bool LoadSingleNode(FILE *f);
bool LoadTableMhs(FILE *f, nodeAddress N);
bool LoadTableMK(FILE *f, nodeAddress N);
bool LoadTablePMK(FILE *f, nodeAddress N);
bool LoadEdges(FILE *f);
bool LoadSingleEdges(FILE *f);
bool FinalizeTablePMK();
bool FinalizeEdges();

/*
void Load (string FileName);
void LoadNodes(int JumlahLokasi, FILE *f, bool *FatalErr, int *RE, bool *enter);
void ChangeTableAvailability(nodeAddress P, bool *hasTMhs_baru, bool *hasTMK_baru, bool *hasTPMK_baru,FILE *F, bool *FatalErr, int *RE, bool *enter);
void ReLoad (string FileName, bool *FatalErr, int *RE);
void LoadTPMK(FILE *f, string NamaNode, bool *FatalErr, int *RE);
void IshEdges(FILE *f, bool *FatalErr, bool *enter);
void LoadEdges(FILE *f, bool *FatalErr, bool *enter);
*/

void ParseAddConnCommand(Reader R);

void ParseAddSiteCommand(Reader R);

void ParseOpenCommand(Reader R);

void ParseResetCommand(); 

void ParseListCommand(char *Parameter);
void PrintSites(char *Parameter, nodeAddress N);
void PrintEdges(char *Parameter, edgeAddress E);
void PrintAdHoc(char *Parameter, nodeAddress N);
void PreProcessParameter(char *Parameter);
int DetectFalseParameter(char *Parameter);

void ParseSaveCommand(Reader R);
void Save (string FileName, bool *OK);

void ParseCreateCommand(Reader R);

void ParseHelpCommand_PersiapanMode();

void ParseExitCommand_PersiapanMode();




// PROSEDUR MODUS SIMULASI
void ParseCommand_SimulationMode(Reader R);

void ParseRetrieveCommand(bool detailsEnabled);
void ParseRetrieveCommand_TabelMhs(bool detailsEnabled);
void ParseRetrieveCommand_TabelMK(bool detailsEnabled);
void ParseRetrieveCommand_TabelPMK(bool detailsEnabled);

void ParseInsertCommand();
void ParseInsertCommand_TabelMhs();
void ParseInsertCommand_TabelMK();
void ParseInsertCommand_TabelPMK();

void ParseUpdateCommand();
void ParseUpdateCommand_TabelMhs();
void ParseUpdateCommand_TabelMK();
void ParseUpdateCommand_TabelPMK();

void ParseDeleteCommand();
void ParseDeleteCommand_TabelMhs();
void ParseDeleteCommand_TabelMK();
void ParseDeleteCommand_TabelPMK();

void ParseExitCommand_SimulationMode();

void ParseHelpCommand_SimulationMode();

#endif
